<template>
	<view v-if="list.length > 0">
		<view v-for="(item, index) in list" :key="index">
			<u-cell :isLink="true" :border="true" @click="navigateTo(`/pages/work/check/checkDetail?checkOrder=${item.checkOrder}&checkType=${item.checkType}`)">
				<view slot="title" class="notice-record-title"><text>盘点单</text>[{{item.checkOrder}}]</view>
				<view slot="label" class="notice-record-desc">
					<u-line length="106%"></u-line>
					<view style="display: flex;justify-content: space-between;margin: 10rpx 0;">
						<view>{{ item.createTime }}</view>
						<view>{{ getStatusType(item.status) }}</view>
					</view>
				</view>
			</u-cell>
			<u-gap height="10" bgColor="#ebebeb"></u-gap>
		</view>
		<u-loadmore :status="status" />
		<u-toast ref="uToast"></u-toast>
	</view>
	<u-empty
		v-else
		mode="list"
		icon="http://cdn.uviewui.com/uview/empty/list.png"
	>
	</u-empty>
</template>

<script>
	import { checkOrder } from '@/api/work/check.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				query: {
					pageNo: 1,
					pageSize: 10
				},
				list: [],
				total: 0,
				loadFinish:false
			};
		},
		onShow() {
			this.toQuery()
		},
		methods: {
			// 查詢
			async toQuery() {
				const res = await checkOrder(this.query)
				this.list = res.records
				this.total = res.total
				if(this.total < this.query.pageSize) {
					this.loadFinish = true
					this.status = 'nomore'
				}
			},
			// 手动字典
			getStatusType(val) {
				switch(val) {
					case 0:
						return '未执行';
					case 1:
						return '执行中';
					case 2:
						return '已完成';
					default:
						return '未知状态';
				}
			},
			// 跳轉
			navigateTo(url) {
				uni.navigateTo({
					url:url
				})
			},
			async onReachBottom() {
				this.status = 'loading';
				if(this.loadFinish) {
					this.status = 'nomore'
					this.$refs.uToast.show({
						type: 'warning',
						message: "盘点单已加载完毕"
					})
					return
				} else {
					this.query.pageNo++
				}
				const res = await checkOrder(this.query)
				this.list.push(...res.records)
				this.total = res.total
				this.status = 'loadmore'
				if( this.query.pageNo * this.query.pageSize > res.total ) {
					this.loadFinish = true
					this.status = 'nomore'
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
/deep/.u-cell__body {
	padding: 12rpx !important;
	align-items: start;
}
	
.notice-record-title {
	margin: 10px 0;
}
.notice-record {
  display: flex;
  padding: 0;

  &-content {
    margin-left: 8px;
  }

  &-title {
    font-size: 28rpx;
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  &-title .read {
    color: #ccc;
  }

  &-desc {
    padding: 4px 0;
    font-size: 12px;
    color: #909399;
    // display: flex;
  }
}
</style>
